package lab03.test12;

import java.sql.*;

public class Test12 {
    public static void main(String[] args) {
//        查询所有记录；
//        查询用户名为'admin'的记录；
//        查询用户名为'admin'，密码为'123456'的记录；
//        查询注册时间大于10000000的记录；

        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;


        String sql="select * from t_users";   // 查询所有记录
        String sql1="select * from t_users where username='admin'";      // 查询用户名为'admin'的记录
        String sql2="select * from t_users where username='admin' and password='123456'";    //查询用户名为'admin'，密码为'123456'的记录
        String sql3="select * from t_users where register_datetime>10000000";

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection=DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "444455"
                    );

            statement=connection.createStatement();
            statement.execute(sql);
            statement.execute(sql1);
            statement.execute(sql2);
            statement.execute(sql3);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }


}

